@extends('layout.master')

@section('title','积分商城实体发货')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')


    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">拒绝理由</h4>
                </div>
                <div class="modal-body">
                    <div class="floating-labels role-edit">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="check-content" name="check_content"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">理由</label>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success"
                                                        onclick="refuse({{ $operationRecord->id }})"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="express" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">填写快递信息</h4>
                </div>
                <div class="modal-body">
                    <div class="floating-labels express" id="express">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="express-name" name="express_name" required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">快递名称</label>
                            </div>
                            <div class="form-group m-b-40">
                                <input type="text" class="form-control" id="express-order" name="express_order"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input2">快递单号</label>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" onclick="deliver({{ $operationRecord->id }})"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">

        <div class="col-lg-12 col-md-12">
            <div class="white-box">
                <div class="form-horizontal form-material" id="deliver">
                    <div class="row">
                        <div class="col-md-12 col-sm-8">
                            <div class="row">
                                <div class="col-md-3 col-sm-6">
                                    <div class="form-group">
                                        <label class="col-md-12">收货人</label>
                                        <div class="col-md-12">
                                            <input type="text" value="{{ $operationRecord->user_name }}"
                                                   class="form-control form-control-line" readonly>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3 col-sm-6">
                                    <div class="form-group">
                                        <label class="col-md-12">收货人电话</label>
                                        <div class="col-md-12">
                                            <input type="text" value="{{ $operationRecord->phone }}"
                                                   class="form-control form-control-line" readonly>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6 col-sm-12">
                                    <div class="form-group">
                                        <label class="col-md-12">收货地址</label>
                                        <div class="col-md-12">
                                            <input type="text"
                                                   value="{{ $operationRecord->sheng . '省' .  $operationRecord->shi . '市' .  $operationRecord->xian .  $operationRecord->detail}}"
                                                   class="form-control form-control-line" readonly>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-12 col-sm-12">
                                    <div class="form-group">
                                        <label class="col-md-12">商品名称</label>
                                        <div class="col-md-12">
                                            <input type="text" value="{{ $commodity->title }}"
                                                   class="form-control form-control-line" readonly>
                                        </div>
                                    </div>
                                </div>
                                @if($operationRecord->status === \App\OperationRecord::STATUS_YES)
                                    <div class="col-md-12 col-sm-12">
                                        <div class="form-group">
                                            <label class="col-md-12">快递</label>
                                            <div class="col-md-12">
                                                <input type="text"
                                                       value="{{ $operationRecord->express_name . ": " . $operationRecord->express_order }}"
                                                       class="form-control form-control-line" readonly>
                                            </div>
                                        </div>
                                    </div>
                                @endif

                                @if($operationRecord->status === \App\OperationRecord::STATUS_NO)
                                    <div class="col-md-12 col-sm-12">
                                        <div class="form-group">
                                            <label class="col-md-12">拒绝理由</label>
                                            <div class="col-md-12">
                                                <input type="text" value="{{ $operationRecord->check_content }}"
                                                       class="form-control form-control-line" readonly>
                                            </div>
                                        </div>
                                    </div>
                                @endif
                            </div>

                            <div class="form-group">
                                <a class="fcbtn btn btn-success btn-outline btn-1e waves-effect"
                                   href="{{ url('/operationRecord/list') }}">返回列表
                                </a>
                                @if($operationRecord->status === \App\OperationRecord::STATUS_WAITING)
                                    <button class="btn btn-success btn-outline" data-toggle='modal'
                                            data-target='#express'>通过
                                    </button>
                                    <button class="btn btn-info btn-outline" data-toggle='modal'
                                            data-target='#exampleModal'>不通过
                                    </button>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection
@section('js')
    @parent
    <!-- icheck -->
    <script src="{{ asset('plugins/bower_components/icheck/icheck.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/icheck/icheck.init.js') }}"></script>
    <script src="{{ asset('js/jasny-bootstrap.js') }}"></script>
    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/summernote/dist/summernote.min.js') }}"></script>
    <script>
        $(document).ready(function () {
            // Basic
            $('.dropify').dropify();
        });
    </script>
    <script src="{{ asset('plugins/bower_components/bootstrap-select/bootstrap-select.min.js') }}"
            type="text/javascript"></script>
    <!-- bt-switch -->
    <script src="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.js') }}"></script>
    <script type="text/javascript">
        //拒绝发货
        function refuse(sid) {
            var check_content = $("#check-content").val();
            swal({
                    title: "",
                    text: "确定不通过么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/operationRecord/no/' + sid,
                        data:{check_content:check_content},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }

        //发货
        function deliver(sid) {
            var express_name = $("#express-name").val();
            var express_order = $("#express-order").val();
            swal({
                    title: "",
                    text: "确定通过么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/operationRecord/deliver/' + sid,
                        data:{express_name: express_name, express_order:express_order},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }

    </script>
@endsection